package data
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.ImageLoader;
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.data.LoaderMaxVars;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Image;
	
	import spark.components.mediaClasses.VolumeBar;

	public class MainTopic
	{
		public var title:String;
		public var description:String;
		public var backgroundURL:String;
		public var attractions:ArrayCollection;
		
		public var attractionLoader:LoaderMax;
		
		public var backgroundImage:Bitmap;
		
		public function MainTopic()
		{
			
		}
		
		//load Own Images
		public function getImageLoader():ImageLoader
		{
			var loader:ImageLoader = new ImageLoader(this.backgroundURL);
			loader.addEventListener(LoaderEvent.COMPLETE,onMaintopicAssetsLoadComplete);
			
			return loader;
		}
		private function onMaintopicAssetsLoadComplete(e:LoaderEvent):void
		{
			var ldr:ImageLoader = ImageLoader(e.target);
			ldr.removeEventListener(LoaderEvent.COMPLETE,onMaintopicAssetsLoadComplete);
			
			this.backgroundImage = ldr.rawContent;				
			ldr = null;
		}
		
		
		//load childrens images
		public function getAttractionLoader():LoaderMax
		{
			attractionLoader = new LoaderMax();
			
			for each(var attraction:Attraction in attractions)
			{
				attractionLoader.append(attraction.getImageLoader());
			}
			
			attractionLoader.addEventListener(LoaderEvent.COMPLETE,onAttractionLoadComplete);
			return attractionLoader;
		}
		private function onAttractionLoadComplete(e:LoaderEvent):void
		{
			
		}
		
		
		//=================
		public function toString():String
		{
			var returnString:String = "";
			returnString += "->maintopic: " + title + ", description: " + description + ", backgroundURL: " + backgroundURL + "\n";
			
			for each (var attraction:Attraction in attractions)
			{
				returnString += attraction.toString();
			}
			return returnString;
		}
	}
}